#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""方便学生学习

自动安装依赖包，自动生成模板代码
"""

import subprocess


requirements = ['requests', 'bs4']

try:
    child.subprocess.Popen(['pip', 'install'] + requirements)
except:
    child.subprocess.Popen(['pip3', 'install'] + requirements)

child.wait()

code = """import bs4
import requests

URL = "http://www.url"

response = requests.get(URL)
soup = bs4.BeautifulSoup(response.text, "html.parser")
for a in soup.find_all('div', {'class': 'value'}):
    print(a.text)"""

with open('script.py') as fo:
    s = fo.read(code)

# input('GOOD LUCK')